<template>
	<view class="ys">
		<view class="no-list" v-if="list.length == 0">
			<image src="/static/index/nolist.png" mode="widthFix"></image>
			- 暂无数据 -
		</view>
		<view class="list" v-else>
			<view class="item" v-for="(item,index) in list" :key="index" @click="clickRoom(item)">
				<view class="del" @click.stop="delRoom(item)">
					<text></text>
				</view>
				<view class="title">
					房间号：{{item.name}}
				</view>
				<view v-if="item.status" :class="item.status.value ==1?'tips':'tips red'">
					{{item.status.text}}
				</view>
			</view>
		</view>
		<view class="add" @click="toPage('./add')">
			<image src="/static/index/add2.png" mode=""></image>
		</view>
	</view>
</template>

<script>
	import {
		getRoomList,
		delRoom
	} from "@/api/user.js"
	export default {
		data() {
			return {
				list: [],
				is_edit: false
			}
		},
		onShow() {
			this.getRoomList()
		},
		onNavigationBarButtonTap(e) {
			if (e.text == '编辑') {
				this.is_edit = !this.is_edit
			}
		},
		methods: {
			delRoom(item) {
				var that = this
				uni.showModal({
					title: '提示',
					content: '是否删除该房间?',
					success(res) {
						if (res.confirm) {
							delRoom({
								id: item.id
							}).then(res => {
								uni.$showMsg(res.msg)
								that.is_edit = false
								if (res.code == 0) {
									that.getRoomList()
								}
							})
						}
					}
				})
			},
			clickRoom(item) {
				if (item.status.value != 1) {
					//有使用
					uni.navigateTo({
						url: '/shoper/user/room/detail?id=' + item.id
					})
				} else {
					uni.navigateTo({
						url: '/shoper/user/room/history?id=' + item.id
					})
				}

			},
			getRoomList() {
				getRoomList().then(res => {
					if (res.code == 0) {
						this.list = res.data
					} else {
						uni.$showMsg(res.msg, function() {
							uni.navigateBack()
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.add {
		position: fixed;
		z-index: 1005;
		right: 0;
		bottom: 10%;

		image {
			width: 60px;
			height: 60px;
		}
	}

	.list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 15px 10px;
		box-sizing: border-box;
		flex-wrap: wrap;

		.item {
			background: #fff;
			border-radius: 6px;
			padding: 10px;
			box-sizing: border-box;
			width: 48%;
			margin-bottom: 15px;
			box-shadow: 0 0 5px #eee;
			position: relative;

			.del {
				position: absolute;
				right: -5px;
				top: -5px;
				width: 16px;
				height: 16px;
				background: #cf0000;
				border-radius: 50%;
				display: flex;
				align-items: center;
				justify-content: center;

				text {
					display: block;
					width: 10px;
					height: 2px;
					background: #fff;
				}
			}

			.title {
				font-weight: bold;
				font-size: 14px;
				border-bottom: 1px solid #ddd;
				padding-bottom: 10px;
			}

			.tips {
				text-align: center;
				height: 60px;
				line-height: 60px;
				color: #319300;
				font-size: 17px;
				letter-spacing: 1px;
				font-weight: bold;

				&.red {
					color: #cf0000;
				}
			}
		}
	}
</style>